function buildWebSocket() {
    //检查浏览器是否支持WebSocket
    if (!window.WebSocket) {
        console.log('您的浏览器不支持WebSocket');
    }
    var el = document.getElementById("textarea1");
    if (window.myWSClient && window.myWSClient.readyState == 1) {
        return;
    }
    var wsClient = new WebSocket('ws://{NGURL}/wsRobot');
    window.myWSClient = wsClient;
    //连接
    wsClient.open = function (e) {
        el.value += "连接到了！\r\n";
        isConnected = true;
    }
    wsClient.onclose = function (e) {
        el.value += "突然你就走了，断开了！\r\n";
        isConnected = false;
    }
    //接收
    wsClient.onmessage = function (e) {
        var edata = e.data;
        if (edata.startsWith("GetPageViewCount")) {
            return;
        }
        if (edata.startsWith('GetJikeComments')) {
            if (onGetJikeCommentsHandler != null) {
                onGetJikeCommentsHandler(edata.substr('GetJikeComments'.length + 1));
            }
            return;
        }
        if (edata.startsWith('GetJikeTagData')) {
            if (onGetJikeTagDatHandler != null) {
                onGetJikeTagDatHandler(edata.substr('GetJikeTagData'.length + 1));
            }
            return;
        }
        var t1 = edata.indexOf(':');
        var key = edata.substr(0, t1);
        var value = edata.substr(t1 + 1);

        if (commonHandlers[key]) {
            commonHandlers[key](value);
            return;
        }

        alert(edata);
    }
    wsClient.onerror = function (e) {
        el.value += "连接失败！结果：" + e.data + "\r\n";
    }
}
//发送
function sendData(msg) {
    if (isConnected == false) {
        connectWaitCount = 0;
        buildWebSocket();
        setTimeout(function () {
            myWSClient.send(msg);
        }, 1000);
    }
    else {
        myWSClient.send(msg);
    }
}
//下面是获得数据的
var isConnected = false;
var connectWaitCount = 0;
var onGetJikeCommentsHandler;
var onGetJikeTagDatHandler;
var commonHandlers = {};
function addHandler(name, handler) {
    commonHandlers[name] = handler;
}

